import request from './request'

export interface ApiResponse<T = any> {
  code: number
  message: string
  data: T
}

export interface User {
  id: number
  account: string
  name: string
  email: string
  phone: string
  sex: number
  deptCode: string
  deptName: string
  isAdmin: boolean
  createdAt: string
  updatedAt: string
  createBy: number
}

export interface CreateUserRequest {
  account: string
  name: string
  email: string
  password: string
  phone: string,
  sex: number,
  deptCode: string,
  isAdmin: boolean
}

export interface UpdateUserRequest {
  id: number
  account: string
  email: string
  phone: string,
  sex: number,
  deptCode: string,
  isAdmin: boolean
}

export interface ResetPasswordRequest {
  userId?: number,
  oldPassword?:string,
  newPassword: string,
  confirmPassword: string,

}

export interface UserListParams {
  keyWord?: string
  deptCode?: string
  pageDto: {
    pageNumber: number
    pageSize: number
  }
}

export interface PagedResult<T> {
  items: T[]
  totalCount: number
  pageNumber: number
  pageSize: number
}

// 获取用户列表
export const getUserList = (params: UserListParams): Promise<ApiResponse<PagedResult<User>>> => {
  return request.post('/user/getList', params)
}

// 创建用户
export const createUser = (data: CreateUserRequest): Promise<any> => {
  return request.post('/user/addUser', data)
}

// 更新用户
export const updateUser = (data: UpdateUserRequest): Promise<any> => {
  return request.post('/user/updateUser', data)
}

// 删除用户
export const deleteUser = (id: number): Promise<any> => {
  return request.post('/user/delById', { id })
}

// 重置密码
export const resetPassword = (data: ResetPasswordRequest): Promise<any> => {
  return request.post('/auth/resetPassword', data)
}

// 重置用户密码
export const resetUserPassword = (data: ResetPasswordRequest): Promise<any> => {
  return request.post('/user/resetUserPassword', data)
}

// 更新用户信息
export const updateUserInfo = (data: UpdateUserRequest): Promise<any> => {
  return request.post('/auth/updateInfo', data)
}
